<template>
  <div class="district-card" v-if="district || console.log(district)">
    <div class="district-header">
      <h4>{{ district.区名 || ''}}</h4>
      <span class="supply-status" :class="getSupplyClass(district.供需状态)">{{ district.供需状态 || '' }}</span>
    </div>
    <div class="water-stats">
      <div class="stat-group">
        <div class="stat-title">需水量(亿m³)</div>
        <div class="stat-row">
          <div class="stat-item">
            <div class="stat-label">生活</div>
            <div class="stat-value">{{ parseFloat(district.需水?.生活需水) || 0 }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">农业</div>
            <div class="stat-value">{{ parseFloat(district.需水?.农业需水) || 0 }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">工业</div>
            <div class="stat-value">{{ parseFloat(district.需水?.工业需水) || 0 }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">生态</div>
            <div class="stat-value">{{ parseFloat(district.需水?.生态需水) || 0 }}</div>
          </div>
          <div class="stat-item total">
            <div class="stat-label">总计</div>
            <div class="stat-value">{{ parseFloat(district.需水?.总需水) || 0 }}</div>
          </div>
        </div>
      </div>
      <div class="stat-group">
        <div class="stat-title">供水量(亿m³)</div>
        <div class="stat-row">
          <div class="stat-item">
            <div class="stat-label">生活</div>
            <div class="stat-value">{{ parseFloat(district.供水?.生活供水) || 0 }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">农业</div>
            <div class="stat-value">{{ parseFloat(district.供水?.农业供水) || 0 }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">工业</div>
            <div class="stat-value">{{ parseFloat(district.供水?.工业供水) || 0 }}</div>
          </div>
          <div class="stat-item">
            <div class="stat-label">生态</div>
            <div class="stat-value">{{ parseFloat(district.供水?.生态供水) || 0 }}</div>
          </div>
          <div class="stat-item total">
            <div class="stat-label">总计</div>
            <div class="stat-value">{{ parseFloat(district.供水?.总供水) || 0 }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';
const props = defineProps({
  district: {
    type: Object,
    required: true
  }
});

const getSupplyClass = (status) => {
  return status.includes('缺水') ? 'shortage-text' : 'balanced-text';
};
</script>

<style scoped lang="scss">
@use "sass:math";

$dark-bg: #1a1a1a;
$card-bg: #222;
$highlight-bg: #2a2a2a;
$text-primary: #e0e0e0;
$text-secondary: #aaa;
$text-highlight: #fff;
$border-color: #333;
$shadow-color: rgba(0, 0, 0, 0.3);
$shortage-color: #ef5350;
$balanced-color: #66bb6a;

$spacing-unit: 0.5rem;
$card-padding: 0.875rem;

.district-card {
  background-color: $card-bg;
  border-radius: 0.5rem;
  padding: $card-padding;
  margin-bottom: $spacing-unit;
  box-shadow: 0 2px 8px $shadow-color;
  transition: transform 0.2s, box-shadow 0.2s;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px $shadow-color;
  }
}

.district-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  
  h4 {
    color: $text-highlight;
    font-size: 0.9375rem;
    margin: 0;
  }
}

.supply-status {
  padding: 0.0625rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
}

.shortage-text {
  color: $shortage-color;
  font-weight: bold;
}

.balanced-text {
  color: $balanced-color;
}

.water-stats {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stat-group {
  background-color: $highlight-bg;
  border-radius: 0.375rem;
  padding: 0.5rem;
}

.stat-title {
  color: #ddd;
  font-weight: bold;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.25rem;
}

.stat-item {
  text-align: center;
  padding: 0.25rem;
  border-radius: 0.25rem;
  transition: all 0.2s;
  
  &:hover {
    background-color: rgba(255, 255, 255, 0.05);
  }
}

.stat-label {
  color: $text-secondary;
  font-size: 0.6875rem;
  margin-bottom: 0.125rem;
}

.stat-value {
  color: $text-primary;
  font-size: 0.8125rem;
}

.stat-item.total {
  .stat-label {
    color: #ccc;
  }
  
  .stat-value {
    font-weight: bold;
  }
}
</style>